#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QDebug>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    file = new QFile("./test.json", this);
    if(file->exists())
    {
        if(!file->open(QIODeviceBase::ReadWrite))
        {
            qDebug() << "打开文件失败";
            return;
        }
    }
    else
    {
        if(!file->open(QIODeviceBase::ReadWrite | QIODeviceBase::NewOnly))
        {
            qDebug() << "文件打开失败";
            return;
        }
    }


    QJsonDocument js;
    QJsonObject obj;
    obj.insert("user1", "123456");
    obj.insert("user2", "1234");

    QJsonArray arr;
    arr.insert(0, "test");
    arr.insert(0, "test2");
    obj.insert("user3", arr);
    js.setObject(obj);
    file->write(js.toJson());

}

MainWindow::~MainWindow()
{
    delete ui;
}

